<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010 Gio CMS (http://www.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 */
?>
<?php if (isset($this->videos) && $this->videos) : ?>
<div class="ninhgio fl pdl5">
	<div class="box video_clip" id="latestVideo">
		<div class="hdr">
			<div class="left"><span></span></div>
			<div class="center"><a href="javascript: void(0);">VIDEO CLIP</a></div>
			<div class="right"><span></span></div>
		</div>
		<div class="bd" style="clear: both;">
			<div class="vachngan"><span></span></div>    
		    <div class="video_content">
				<div style="padding: 5px;">
					<a href="javascript: void(0);" class="color_535353 bgNone video" id="topVideo">
				       	<strong><?php echo $this->topVideo['title']; ?></strong>
				       	<input type="hidden" value="<?php echo $this->topVideo['image_url']; ?>" />
				       	<input type="hidden" value="<?php echo $this->topVideo['file_url']; ?>" />
				    </a>
				</div>
				<div id="divFlvMovieContainer" style="margin:9px 12px 0;">
			    	<div id="divFlvMovie"></div>
			    </div>
			    <div class="videoList" id="lastVideoContainer">
			    	<ul>
			    	<?php foreach ($this->videos as $index => $video) : ?>
				        <?php if ($index > 0) : ?>
						<li>
							<a class="color_535353 video" href="javascript: void(0);">
							<?php echo $video['title']; ?>
							<input type="hidden" value="<?php echo $video['image_url']; ?>" />
				        	<input type="hidden" value="<?php echo $video['file_url']; ?>" />
							</a>
						</li>
						<?php endif; ?>
					<?php endforeach; ?>
					</ul>
			    </div>
			</div>
		</div>
		<div class="ftr">
			<div class="left"></div>
			<div class="center"></div>
			<div class="right"></div>
		</div>
		<div style="clear: both;"></div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	var image = '<?php echo $this->topVideo['image_url']; ?>';
	var file = '<?php echo $this->topVideo['file_url']; ?>';
	playVideo(file, image, false);
		
	$("#lastVideoContainer").find('a.video').each(function() {
		$(this).click(function() {
			var image = $(this).find('input:first[type="hidden"]').attr('value');
			var file = $(this).find('input:last[type="hidden"]').attr('value');
			var title = $(this).text();
			
			var topVideo = $('#topVideo');
			var topImage = $(topVideo).find('input:first[type="hidden"]').attr('value');
			var topFile = $(topVideo).find('input:last[type="hidden"]').attr('value');
			var topTitle = $(topVideo).text();
			
			$(topVideo).find('strong:first').html(title);
			$(topVideo).find('input:first[type="hidden"]').val(image);
			$(topVideo).find('input:last[type="hidden"]').val(file);

			$(this).html(topTitle);
			var input1 = $('<input/>');
			var input2 = $('<input/>');
			$(input1).attr('type', 'hidden').val(topImage);
			$(input2).attr('type', 'hidden').val(topFile);
			$(input1).appendTo(this);
			$(input2).appendTo(this);

			playVideo(file, image, true);
		});
	});
});

function playVideo(file, image, auto) {
	var flashvars = {
		play: true,
		repeat: true, 
		autostart: auto + '',
		file: file	
	};
	if (image != null && image != '') {
		flashvars.image = image;
	}
	var params = {
		allowfullscreen: 'true', 
		allowscriptaccess: 'always',
		menu: false
	};
	swfobject.embedSWF('<?php echo $this->APP_STATIC_SERVER; ?>/js/flvplayer/new_player.swf', 'divFlvMovie', '275', '238', '9.0.0', '<?php echo $this->APP_STATIC_SERVER; ?>/js/swfobject/expressInstall.swf', flashvars, params, {});
}
</script>
<?php endif; ?>